<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="https://cdn.bootcdn.net/ajax/libs/velocity/1.2.3/velocity.min.js"></script>

    <div id="app">
      Fade In:<input
        type="range"
        v-model="fadeInDuration"
        min="0"
        :max="maxFadeDuration"
      />
      Fade Out:<input
        type="range"
        v-model="fadeOutDuration"
        min="0"
        :max="maxFadeDuration"
      />
      <transition
        :css="false"
        :before-enter="beforeEnter"
        :enter="enter"
        :leave="leave"
      >
        <p v-if="show">hello</p>
      </transition>
      <button type="button" v-if="stop" @click="stop=false">
        Start animating
      </button>
      <button type="button" v-else @click="stop=true">Stop it!</button>
    </div>
    <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
  
    <script>
      new Vue({
        el: "#app",
        data: {
          show: true,
          fadeInDuration: 1000,
          fadeOutDuration: 1000,
          maxFadeDuration: 1500,
          stop: true,
        },
        mounted: function () {
          // this.show=false
        },
        methods: {
          beforeEnter: function (el) {
            el.style.opacity = 0;
          },
          enter: function (el, done) {
            var vm = this;
            Velocity(
              el,
              { opacity: 1 },
              {
                duration: this.fadeInDuration,
                complete: function () {
                  done();
                  if (!vm.stop) vm.show = false;
                },
              }
            );
          },
          leave: function (el, done) {
            var vm = this;
            Velocity(
              el,
              { opacity: 0 },
              {
                duration: this.fadeOutDuration,
                complete: function () {
                  done(), (vm.show = true);
                },
              }
            );
          },
        },
      });
    </script>
  </body>
</html>
